import axios from './axios'
import qs from 'qs'
import { baseUrl } from '@/config/config'
// 店铺管理
// 签约管理列表
export const signPage = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/sign/course/page',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 签约管理详情
export const signGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/sign/course/get',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 签约管理列表
export const signAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/sign/course/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 签约管理列表
export const signEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/sign/course/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取店铺列表
export const storeGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/store/list',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增店铺
export const storeAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/store/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 编辑店铺
export const storeEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/store/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 删除店铺
export const storeRemove = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/store/remove',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取店铺详情
export const storeDetailGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/store/getDetailById',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取会员详情
export const memberDetailGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/member/getDetailById',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取会员列表
export const memberPageGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/member/page',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 编辑会员
export const memberEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/member/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 添加会员
export const memberAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/member/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 行政区划相关
export const areaListGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/area/list',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取系统内置字典
export const dicGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/dic/list',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增教练
export const coachAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增教练
export const coachEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 编辑顺序
export const coachEditSort = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/editSort',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取教练
export const coachGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/page',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取可用教练
export const coachEnabledGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/listEnabled',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取教练详情
export const coachDetailGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/getDetailByUserId',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 课程管理新增
export const courseAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/course/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 课程管理编辑
export const courseEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/course/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 课程管理详情
export const courseGetById = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/course/getById',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 课程管理详情
export const courseGetList = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/course/pageList',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取可用协议列表
export const protocolGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/protocol/config/listAll',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取可用协议列表
export const protocolEnabledGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/protocol/config/listEnabled',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 新增协议
export const protocolAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/protocol/config/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 编辑协议
export const protocolEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/protocol/config/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取协议详情
export const protocolGetById = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/protocol/config/getById',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 教练创建预约
export const coachOrderAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/appointment/coachAdd',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取教练已预约的时间列表
export const coachBookedTimeGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/appointment/coachBookedTime',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 签约列表
export const appointmentPage = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/appointment/page',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 预约作废（id为预约id）
export const appointmentCancel = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/appointment/cancel',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 取消预约（id为预约id）
export const disAppointment = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/appointment/cancelAppointment',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 核销（id为预约id）
export const writeOffAppointment = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/appointment/writeOff',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 确认支付
export const confirmPayment = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/confirmPayment',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改密码
export const editPassword = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/editPassword',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 修改密码
export const resetPassword = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/resetPassword',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取支付二维码
export const getPayQr = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/system/config/getPayQr',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// PC端获取我有权的店铺
export const storeListMy = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/store/listMy',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// PC端获取我有权的店铺
export const orderGet = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/order/page',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded' 
      },
      method: 'POST',
      data: qs.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 设备列表
export const deviceList = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/device/list',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 设备新增
export const deviceAdd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/device/add',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 设备编辑
export const deviceEdit = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/device/edit',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 数据统计
export const userStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/userStatistic',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 私教课程消耗统计
export const signCourseUsedStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/signCourseUsedStatistic',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 用户发展趋势
export const userTrends = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/userTrends',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 私教课程消耗比例
export const signCourseUsedRatioStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/signCourseUsedRatioStatistic',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 课程订单金额
export const signCourseNameAndMoneyStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/signCourseNameAndMoneyStatistic',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 订单类型统计
export const signCourseTypeAndMoneyStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/signCourseTypeAndMoneyStatistic',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 教练耗课数
export const statisticGroupByCoachUserIdAndSaleMode = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/statisticGroupByCoachUserIdAndSaleMode',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 教练业绩
export const coachSignStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/coachSignStatistic',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 统计教练耗课金额情况
export const coachSignCourseUsedStatistic = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/coachSignCourseUsedStatistic',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 教练耗课详情
export const selectCoachUsedDetail = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/selectCoachUsedDetail',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取我可见的教练列表
export const coachVisibleList = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/users/coach/visibleList',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 门禁记录
export const pageAccessLog = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/device/pageAccessLog',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 删除签约
export const courseRemove = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/sign/course/remove',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 包时私教课扣费明细
export const selectPrivateTimesUsedDetail = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/selectPrivateTimesUsedDetail',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 自由练耗课统计
export const statisticFreeSignCourseUsedMoney = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/statisticFreeSignCourseUsedMoney',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 自由练耗课总金额
export const sumFreeSignCourseUsedMoney = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/statistic/sumFreeSignCourseUsedMoney',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8' 
      },
      data: JSON.stringify(params)
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
